﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DentScan2.WebApp
{
    public partial class PassChange : Classes.BaseForm
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.CheckLogged();
        }


        private void Save()
        {
            Page.Validate("vgUser");
            if (!IsValid)
                return;
            DB.User usr = dl.Users.Where(user => user.UserId == this.UserId).First();
            usr.Password = Tools.Tools.GetMd5Hash(tbNewPass.Text);            
            dl.SubmitChanges();
            Alert("OK");
        }
        protected void bSave_Click(object sender, EventArgs e)
        {
            Save();
        }

        protected void cvPassword_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = dl.Users.Where(user => user.UserName == this.UserName && user.Password == Tools.Tools.GetMd5Hash(tbPassword.Text)).FirstOrDefault() != null;
        }

        protected void cvNewPass2_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = tbNewPass2.Text == tbNewPass.Text;
        }


    }
}